#! /bin/bash

set -e -x

if [ -n "${AWS_ACCESS_KEY_ID}" ]; then
    sed -i "s@SUBST_AWS_ACCESS_KEY@${AWS_ACCESS_KEY_ID}@g" ${HADOOP_CONF_DIR}/core-site.xml
fi
if [ -n "${AWS_SECRET_ACCESS_KEY}" ]; then
    sed -i "s@SUBST_AWS_SECRET_ACCESS_KEY@${AWS_SECRET_ACCESS_KEY}@g" ${HADOOP_CONF_DIR}/core-site.xml
fi

sudo -E -u hdfs /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR start namenode
sudo -E -u hdfs /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR start secondarynamenode
sudo -E /usr/hdp/current/hadoop-client/sbin/hadoop-daemon.sh --config $HADOOP_CONF_DIR start datanode
